#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    (void)event;
    // 绘图工作就会放到这里来执行
    // 指定往主窗口画
    QPainter painter(this);

    // 画一个线段
    painter.drawLine(20, 20, 200, 20);
    painter.drawLine(QPoint(20, 100), QPoint(200, 100));

    painter.drawLine(20, 20, 100, 300);

    // 画一个矩形
    painter.drawRect(100, 100, 300, 200);

    // 画圆形
    // 画笔
    QPen pen;
    pen.setColor(QColor(255, 0, 0));
    pen.setWidth(5);
    pen.setStyle(Qt::DashLine);
    painter.setPen(pen);

    // 画刷
    QBrush brush;
    brush.setColor(QColor(0, 255, 0));
    brush.setStyle(Qt::CrossPattern);
    painter.setBrush(brush);
    painter.drawEllipse(200, 200, 400, 100);

    QFont font("微软雅黑", 24);
    painter.setFont(font);

    painter.drawText(0, 100, "hello");
}

